package cn.wizzer.app.web.commons.ext.websocket.action.msg.attendant;

import cn.wizzer.app.user.modules.services.UserService;
import cn.wizzer.app.web.commons.ext.websocket.filter.AttendantFilter;
import cn.wizzer.app.web.commons.ext.websocket.filter.TokenFilter;
import cn.wizzer.app.web.commons.ext.websocket.main.action.BaseNettyAction;
import cn.wizzer.app.web.commons.ext.websocket.main.action.NettyAction;
import cn.wizzer.app.web.commons.ext.websocket.main.base.NettyCache;
import cn.wizzer.framework.base.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.Channel;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

/**
 * @author zl   客服登出
 * @date 2020/6/23 17:16
 */
@IocBean
@NettyAction(uri = "/attendant/logout", filters = {TokenFilter.class, AttendantFilter.class})
public class AttendantLogoutAction extends BaseNettyAction {

    @Inject
    @Reference
    private UserService userService;

    @Override
    public Result action(Channel income, JSONObject params) {
        String attendantId = params.getString("appid");
        //离线处理
        userService.update(Chain.make("is_online", 0), Cnd.where("id", "=", attendantId));
        NettyCache.globalRemove(attendantId);
        return Result.success("登出成功");
    }
}
